<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        const arr = [{name:"1"}];
        const arr2 = arr.slice();
        console.log(JSON.stringify(arr));  // 1
        arr2[0].name = "3";
        console.log(JSON.stringify(arr));  // 3

        console.log(JSON.stringify("------"));
        console.log(JSON.stringify(arr))  // 3
        const arr3 = structuredClone(arr);  // 3
        arr3[0].name = 10;
        console.log(JSON.stringify(arr));  // 3
        console.log(JSON.stringify(arr3));  // 10


        // 复制
        /* 
            ...(展开运算符)s
                - 可以将一个数组中的元素展开到另一个数组中或者作为函数的参数传递
        */
        const array = [1,2,3];
        console.log(JSON.stringify(array));
        const array2 = [...array, 4, 5];
        console.log(JSON.stringify(array2));

        /* 
            对象的复制
                - Object.assign(目标对象， 被复制的对象)
                    - 将被复制对象中等 属性复制到目标对象里，并将目标对象返回
        */
        const obj = {name:"孙悟空", age:18};
        console.log(JSON.stringify(obj));
        
        const obj2 = {address:"花果山", name:"猴子"};
        console.log(JSON.stringify(obj2));

        Object.assign(obj2, obj);
        console.log(JSON.stringify(obj2));
        
        obj2.name = "猪八戒";
        obj2.address = "高老庄";
        console.log(JSON.stringify(obj));
        console.log("obj2", JSON.stringify(obj2));

    </script>
</head>
<body>
    
</body>
</html>